# -*- coding: utf-8 -*-
'''
Created on 2011-3-19
根据xml文件的内容把新浪微博的省份和城市代码转换成名称存储到province表中
@author: Tony
'''

from goplay.sinaweibo.models import Province 
from xml.dom.minidom import parse  
  
if __name__ == '__main__':  
    provinces = {}  
    dom = parse("provinces.xml")  
    root = dom.documentElement  
    provinceNodes = root.getElementsByTagName('province')  
    for provinceNode in provinceNodes:
        provinceId=provinceNode.attributes['id'].value  
        provinceName = provinceNode.attributes['name'].value  
        cityNodes = provinceNode.getElementsByTagName('city')
        for cityNode in cityNodes:
            cityName=cityNode.attributes['name'].value
            cityId=cityNode.attributes['id'].value
            p=Province(province_id=provinceId,province_name=provinceName,city_id=cityId,city_name=cityName)
            p.save() 
        provinces[provinceName] = [cityNode.attributes['name'].value for cityNode in cityNodes]  
    print provinces